fix(enr): handle short port values without throwing - #339
Open
nflaig wants to merge 2 commits into
Open
Conversation
wemeetagain
reviewed
Aug 10, 2026
|
|
||
| export function getProtocolValue(kvs: ReadonlyMap<ENRKey, ENRValue>, key: string): number | undefined { | ||
| const raw = kvs.get(key); | ||
| const raw = normalizePortBytes(kvs.get(key)); |
Member
There was a problem hiding this comment.
maybe this should return the number (eg do the bitshift + add)
nflaig
commented
Aug 11, 2026
| @@ -182,20 +182,9 @@ export function getIPValue( | |||
|
|
|||
| export function getProtocolValue(kvs: ReadonlyMap<ENRKey, ENRValue>, key: string): number | undefined { | |||
Member
Author
There was a problem hiding this comment.
should this be renamed to getPortValue? or otherwise could rename the port variable below if we think this will return anything other than a port in the future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
getProtocolValue()reads themundefinedfor empty, zero, or oversized port values instead of throwinggetLocationMultiaddr()getSocketAddressOnENR()pathWhy
A mainnet Lodestar v1.45.0 node using
@chainsafe/enr@6.0.1and@chainsafe/discv5@12.0.1received a signed remote ENR with a shortudpvalue. During session establishment,getSocketAddressOnENR()accessedenr.udp, andgetProtocolValue()threw:ENR ports are big-endian integers, so one-byte values are valid. Invalid values received from untrusted peers should make the ENR non-contactable rather than escape as an exception.
This follows up on the normalization added in #333 and applies it to the direct port getters used by discv5.
Related: ChainSafe/lodestar#7445, ChainSafe/lodestar#9310.
Impact
Valid compact ports now decode correctly. Empty, zero, and oversized values are ignored without disrupting the discv5 session service. Normal two-byte ports are unchanged.
Validation
pnpm buildpnpm lint(passes; two existing warnings outside this change)pnpm check-typespnpm test:unit— 28 ENR tests and 65 discv5 tests passpnpm test:e2e— 5 tests pass